package yonghe
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.filesystem.File;
	import flash.text.TextField;
	import flash.display.Sprite;
	
	public class SayPage extends Sprite
	{
		private static var _main:SayPage = null;
		
		public static function get main():SayPage
		{
			if (_main == null)
				_main = new SayPage();
			return _main;
		}
		
		public function SayPage()
		{
			_main = this;
			addChild(new Bitmap(test.main.bg.bitmapData));
			width = test.stageW;
			height = test.stageH;
			
			resetBtn = new BtnBase(toClear, new Assets.rewrite_png);
			backBtn = new BtnBase(back, new Assets.back_png);
			sendBtn = new BtnBase(toSend, new Assets.upload_png);
			//sendBtn.width = resetBtn.width = backBtn.width = 240;
			//sendBtn.height = resetBtn.height = backBtn.height = 100;
			addChild(sendBtn);
			addChild(resetBtn);
			addChild(backBtn);
			
			backBtn.y = sendBtn.y = resetBtn.y = 40;
			backBtn.x = 1000;
			resetBtn.x = 1300;
			sendBtn.x = 1600;
			
			container = new Sprite();
			container.y = 180;
			addChild(container);
			
			var drawBoardBg:Bitmap;
			drawBoardBg = new Assets.sayBoard_png;
			drawBoardBg.width = 1920;
			drawBoardBg.scaleY = drawBoardBg.scaleX;
			container.addChild(drawBoardBg);
			
			drawBoard = new DrawBoard();
			drawBoard.init(1800, 600);
			drawBoard.x = (drawBoardBg.width - 1800) / 2;
			drawBoard.y = (drawBoardBg.height - 600) / 2;
			container.addChild(drawBoard);
			
			var color:uint = 0x999999;
			txt1 = ViewSet.makeTxtLine("温馨提示：", 45, color);
			txt2 = ViewSet.makeTxtLine("如果您有意见和建议，欢迎在我们这里留言，让我们一起进步！", 30, color);
			txt1.x = txt2.x = 150;
			txt1.y = 900;
			txt2.y = 960;
			addChild(txt1);
			addChild(txt2);
		
		}
		private var sendBtn:BtnBase;
		private var resetBtn:BtnBase;
		private var backBtn:BtnBase;
		private var txt1:TextField;
		private var txt2:TextField;
		
		private var drawBoard:DrawBoard;
		private var container:Sprite;
		
		private function toClear():void
		{
			logs.adds("重签");
			drawBoard.clear();
			//hasSended = false;
		}
		private var index:int = 0;
		
		private function toSend():void
		{
			if (!drawBoard.hasDrawed)
			{
				Toast.show("您还没有留言");
				return;
			}
			/*
			if (hasSended)
			{
				Toast.show("已经发送过了");
				return;
			}
			*/
			logs.adds("发送");
			var file:File = WriteData.saveDisplayObject("advices/" + Datas.date2str() + "_" + Datas.index + "_" + (index) + ".png", container);
			if (file)
			{
				++index;
				
				Toast.show("发送成功");
				//hasSended = true;
				toClear();
			}
			else
			{
				
				Toast.show("发送失败");
			}
		}
		//private static var hasSended:Boolean = false;
		
		private static var indexTxt:TextField;
		
		public static function show():void
		{
			main.visible = true;
			test.main.addChild(main);
			
			indexTxt = Datas.setIndexTxt(indexTxt);
			indexTxt.x = 100;
			main.addChild(indexTxt);
			
			main.toClear();
		}
		
		public static function back():void
		{
			main.visible = false;
			FirstPage.show();
		}
	}
}
